package com.dhcc.sds.base.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.base.entity.SdsQcentityVersionEntity;
import com.dhcc.sds.base.service.ISdsQcentityVersionService;


/**
 * 质控病种版本
 * 
 * @ClassName: SdsQcentityVersionController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:10:47
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcentityversion")
public class SdsQcentityVersionController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqcentityversion/";

	@Autowired
	private ISdsQcentityVersionService sdsQcentityVersionService;
	

    /**
     * 跳转到质控病种版本列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsqcentityversion.html";
    }
	
    /**
     * 跳转到新增质控病种版本
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdsqcentityversion_add.html";
    }
	
	/**
     * 跳转到修改质控病种版本
     */
    @RequestMapping("/to_update/{sdsQcentityVersionId}")
    public String toUpdate(@PathVariable Long sdsQcentityVersionId, Model model) {
        SdsQcentityVersionEntity sdsQcentityVersion = this.sdsQcentityVersionService.selectById(sdsQcentityVersionId);
        model.addAttribute("sdsQcentityVersion",sdsQcentityVersion);
        return PREFIX + "sdsqcentityversion_edit.html";
    }

    /**
     * 获取质控病种版本列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsQcentityVersionEntity> page = new PageFactory<SdsQcentityVersionEntity>().defaultPage();
        List<SdsQcentityVersionEntity> result = this.sdsQcentityVersionService.page(page,params);
        page.setRecords((List<SdsQcentityVersionEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增质控病种版本
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQcentityVersionEntity sdsQcentityVersion) {
        if (CommonUtil.isOneEmpty(sdsQcentityVersion)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsQcentityVersion.insert();
        return R.ok();
    }

    /**
     * 删除质控病种版本
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsQcentityVersionId) {
	
        this.sdsQcentityVersionService.deleteById(sdsQcentityVersionId);

        return R.ok();
    }

    /**
     * 修改质控病种版本
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsQcentityVersionEntity sdsQcentityVersion) {
        if (CommonUtil.isOneEmpty(sdsQcentityVersion)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQcentityVersionEntity old = this.sdsQcentityVersionService.selectById(sdsQcentityVersion.getId());

        old.setQcEntityId(sdsQcentityVersion.getQcEntityId());
        old.setVerCode(sdsQcentityVersion.getVerCode());
        old.setVerDesc(sdsQcentityVersion.getVerDesc());
        old.setVerStatus(sdsQcentityVersion.getVerStatus());
        old.setStartDate(sdsQcentityVersion.getStartDate());
        old.setEndDate(sdsQcentityVersion.getEndDate());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
